<?php
include_once("../../untils/conn.php");

$id = $_POST['id'];
$proxy_acc = $_POST['proxy_acc'];
$rename = $_POST['rename'];
$reuid = $_POST['reuid'];
$phone = $_POST['phone'];
$status = $_POST['status'];
$notes = $_POST['notes'];
$uptime = time();

if ($status == 1) {
    // 更新 rename_table 表
    $sql = "UPDATE rename_table SET status = $status, notes = '$notes', uptime = $uptime WHERE id = $id";
    if (mysqli_query($con, $sql)) {
        // 更新 proxy 表
        $sql = "UPDATE proxy SET proxy_rename = '$rename', proxy_uid = '$reuid', proxy_phone = '$phone', proxy_rename_sta = $status WHERE proxy_acc = '$proxy_acc'";
        if (mysqli_query($con, $sql)) {
            // 弹窗操作成功
            echo "<script>alert('操作成功'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
        } else {
            // 弹窗操作失败
            echo "<script>alert('操作失败'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
        }
    } else {
        // 弹窗操作失败
        echo "<script>alert('操作失败'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
    }
} elseif ($status == 2) {
    // 只更新 rename_table 表
    $sql = "UPDATE rename_table SET status = $status, notes = '$notes', uptime = $uptime WHERE id = $id";
    if (mysqli_query($con, $sql)) {
        // 弹窗操作成功
        echo "<script>alert('操作成功'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
    } else {
        // 弹窗操作失败
        echo "<script>alert('操作失败'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
    }
} else {
    // 弹窗操作失败（未知的 status 值）
    echo "<script>alert('操作失败'); setTimeout(function(){ window.location.href = '../rename.php'; }, 1000);</script>";
}

mysqli_close($con);
?>
